import React from 'react';
import _allChecked from '../filmStore/'

export default class CheckBox extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            checked: this.props.checked || false
        };
        this.handleClick = this.handleClick.bind(this)
    }
    static propTypes = {
     //  name: React.PropTypes.string.isRequired,
        id: React.PropTypes.string.isRequired,
        ok: React.PropTypes.bool
    };
    handleClick(){
        if(this.props.id !== "checkedall"){
            this.setState({
                checked: !this.state.checked
            },function(){
                let opt = {
                    name: this.props.name,
                    other: this.props.other || '',
                    checked: this.state.checked
                };
                this.props.onChange(this.props.id,opt)
            });
        }else{

        }
    };
    render(){
        let _cn = this.state.checked?"checked":"";
        return (
            <div className={_cn} onClick={this.handleClick}><em></em>{this.props.name}<span>{this.props.other}</span></div>
        )
    }
}